﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;

namespace NBFWcfService
{
    // 注意: 如果更改此处的类名“Service1”，也必须更新 Web.config 和关联的 .svc 文件中对“Service1”的引用。

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1 : IService1
    {
        //调用方式：http://localhost:9162/Service1.svc/GetData?value=1 
        //调用的时候，参数名不分大小写。

        [WebGet(BodyStyle = WebMessageBodyStyle.WrappedRequest , ResponseFormat = WebMessageFormat.Json)] 
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, Method = "POST")]
        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }

        [WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest , RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, Method = "POST")]
        public List<CompositeType> GetDataUsingDataContract(CompositeType ct1, CompositeType ct2)
        {
            if (ct1 != null && ct2 != null)
            {
                List<CompositeType> list = new List<CompositeType>();
                ct1 = GetDataUsingDataContract(ct1);
                ct2 = GetDataUsingDataContract(ct2);
                list.Add(ct1);
                list.Add(ct2);
                return list;
            }
            return null;
        }
    }
}
